<template>
  <div>
    <el-card shadow="never" class="ivu-mt" :body-style="{padding:0}">
      <div class="padding-add">
        <el-form
            ref="curlFrom"
            :model="from"
            :label-width="labelWidth"
            :label-position="labelPosition"
            inline
            @submit.native.prevent
        >
          <el-form-item label="相册名称：" label-for="name">
            <el-input
                v-model="from.name"
                placeholder="请输入相册名称"
                class="form_content_width"
            />
          </el-form-item>

          <el-form-item label="所属院校" label-for="universit_id">
            <el-select v-model="from.universit_id" clearable filterable>
              <el-option
                  v-for="item in universitList"
                  :key="item.id"
                  :label="item.universit_name"
                  :value="item.id">
              </el-option>
            </el-select>
          </el-form-item>

          <el-form-item>
            <el-button type="primary" @click="searchs">查询</el-button>
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card shadow="never" dis-hover class="ivu-mt mt16">
      <el-row type="flex">
        <el-col v-bind="grid">
          <el-button v-auth="['universit_album-add']" type="primary" icon="md-add" @click="add">添加</el-button>
        </el-col>
      </el-row>
      <el-table
          :data="dataList"
          ref="table"
          class="mt25"
          :loading="loading"
          highlight-current-row
      >
        <el-table-column prop="name" label="相册名称">
        </el-table-column>
        <el-table-column prop="universit_name" label="关联院校">
        </el-table-column>
        <el-table-column label="照片">
          <template slot-scope="scope">
            <div class="tabBox_img" v-viewer>
              <img v-lazy="img" v-for="img in scope.row.album_label" />
            </div>
          </template>
        </el-table-column>

        <el-table-column prop="sort" label="排序">
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <a @click="show(scope.row)">详情</a>
            <el-divider direction="vertical" />
            <a @click="edit(scope.row.id)">修改</a>
            <el-divider direction="vertical" />
            <a @click="del(scope.row, '删除', scope.$index)">删除</a>
          </template>
        </el-table-column>
      </el-table>
      <div class="acea-row row-right page">
        <pagination :total="total"  @pagination="pageChange"  :limit.sync="from.limit" :page.sync="from.page" />
      </div>
    </el-card>

    <el-dialog title="查看详情" :visible.sync="dialogTableVisible" v-if='dialogTableVisible'>
      <el-descriptions>
        <el-descriptions-item label="自增ID">{{info.id}}</el-descriptions-item>
        <el-descriptions-item label="相册名称">{{info.name}}</el-descriptions-item>
        <el-descriptions-item label="关联院校">{{info.universit_name}}</el-descriptions-item>
        <el-descriptions-item label="照片">
          <el-image v-for="item in info.album_label" :src="item" :preview-src-list="info.album_label">
          </el-image>
        </el-descriptions-item>
<!--        <el-descriptions-item label="排序">{{info.sort}}</el-descriptions-item>-->
<!--        <el-descriptions-item label="添加时间">{{info.create_time}}</el-descriptions-item>-->
<!--        <el-descriptions-item label="修改时间">{{info.update_time}}</el-descriptions-item>-->
<!--        <el-descriptions-item label="伪删除">{{info.delete_time}}</el-descriptions-item>-->

      </el-descriptions>
    </el-dialog>

  </div>
</template>

<script>
import { mapState } from 'vuex';
import { universitAlbumSaveApi, universitAlbumStatusApi, universitAlbumDeleteApi, universitAlbumUpdateApi, getUniversitAlbumCreateApi, getUniversitAlbumEditApi, getUniversitAlbumListApi, getUniversitAlbumReadApi} from '@/api/crud/universitAlbum';
import {getUniversitListAll} from "@api/crud/universit";
export default {
  name: 'universit_album',
  data() {
    return {
      grid: {
        xl: 7,
        lg: 7,
        md: 12,
        sm: 24,
        xs: 24,
      },
      loading: false,
      from: {
        name:'',
        universit_id: '',
        page: 1,
        limit: 15,
      },
      dataList: [],
      total: 0,
      dialogTableVisible: false,
      info: {},
      universitList: [],
    };
  },
  computed: {
    ...mapState('media', ['isMobile']),
    labelWidth() {
      return this.isMobile ? undefined : '75px';
    },
    labelPosition() {
      return this.isMobile ? 'top' : 'left';
    },
  },
  created() {
    getUniversitListAll().then((res) => {
      this.universitList = res.data;
    })
    this.getList();
  },
  methods: {
    show(row) {
      getUniversitAlbumReadApi(row.id).then(res => {
        this.dialogTableVisible = true;
        this.info = res.data;
      }).catch(res => {
        this.$Message.error(res.msg);
      })
    },
    //修改状态
    updateStatus(row, field) {
      universitAlbumStatusApi(row.id, {field: field, value: row[field]})
          .then(async (res) => {
            this.$message.success(res.msg);
          })
          .catch((res) => {
            this.$message.error(res.msg);
          });
    },
    // 添加
    add() {
      this.$modalForm(getUniversitAlbumCreateApi()).then(() => this.getList());
    },
    // 表格搜索
    searchs() {
      this.from.page = 1;
      this.getList();
    },
    //列表
    getList() {
      this.loading = true;
      getUniversitAlbumListApi(this.from)
          .then(async (res) => {
            let data = res.data;
            this.dataList = data.list;
            this.total = data.count;
            this.loading = false;
          })
          .catch((res) => {
            this.loading = false;
            this.$Message.error(res.msg);
          });
    },
    //分页
    pageChange(index) {
      this.from.page = index;
      this.getList();
    },
    // 修改
    edit(id) {
      this.$modalForm(getUniversitAlbumEditApi(id)).then(() => this.getList());
    },
    // 删除
    del(row, tit, num) {
      let delfromData = {
        title: tit,
        num: num,
        url: `crud/universit_album/${row.id}`,
        method: 'DELETE',
        ids: '',
      };
      this.$modalSure(delfromData)
          .then((res) => {
            this.$Message.success(res.msg);
            this.getList();
          })
          .catch((res) => {
            this.$Message.error(res.msg);
          });
    },
  },
};
</script>

<style scoped lang="stylus"></style>
